package com.safe.app.config.init;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.safe.app.config.oos.CloudStorageServiceImpl;
import com.safe.app.config.oos.config.QiniuCloudConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.stereotype.Component;

/**
 * @author h2l
 * @date 2019/1/8 10:14
 */
@Component
public class CommonConfig {

    /**
     * 接收json字段忽略空字段处理
     *
     * @return
     */
    @Bean
    public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
        MappingJackson2HttpMessageConverter converter =
                new MappingJackson2HttpMessageConverter(mapper);
        return converter;
    }

    /**
     * 云存储服务
     *
     * @param qiniuCloudConfig 云存储基础配置信息
     */
    @Bean
    CloudStorageServiceImpl cloudStorageService(QiniuCloudConfig qiniuCloudConfig) {
        return new CloudStorageServiceImpl(qiniuCloudConfig);
    }
}

